package com.juku2024.juku.dialog

import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.juku2024.juku.R
import com.juku2024.juku.WatchingActivity
import com.juku2024.juku.tools.DisplayUtil

class VideoUpdateDialog(context: Context, style: Int = R.style.CommonDialogStyle): Dialog(context, style) {

    private lateinit var tvDialogMsg: TextView
    private lateinit var btnCancel: Button
    private lateinit var btnConfirm: Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_video_update)

        tvDialogMsg = findViewById(R.id.tv_dialog_msg)
        btnCancel = findViewById(R.id.btn_confirm)
        btnConfirm = findViewById(R.id.btn_cancel)

        btnConfirm.requestFocusFromTouch()
        btnConfirm.setOnClickListener {
            dismiss()
        }
        btnCancel.setOnClickListener {
            dismiss()
            val intent = Intent(context, WatchingActivity::class.java)
            context.startActivity(intent)
        }
    }

    fun showDialog(isFull: Boolean){
        val msg = if (isFull) {
            "“追剧表单”已满，请先取消其他剧，再添加本剧"
        } else {
            "本剧已经添加到“追剧表单”，请在首页查看"
        }
        tvDialogMsg.text = msg
        if (isFull) {
            btnCancel.visibility = View.VISIBLE
        } else {
            btnCancel.visibility = View.GONE
        }
        show()
    }


    override fun onStart() {
        super.onStart()
        val dialogHeight = DisplayUtil.dp2px(context, 190f)
        val dialogWight = DisplayUtil.dp2px(context, 300f)
        window!!.setLayout(dialogWight, dialogHeight)
        setCanceledOnTouchOutside(false) //点击边际可消失
    }



}